angular.module('mamApp').controller('adjustPlayControlModalController', ['$scope', '$uibModalInstance', 'PlayControlManager', 'param', '$filter',
    function ($scope, $uibModalInstance, PlayControlManager, param, $filter) {
        $scope.data = {};

        var ids = param.ids;


        $scope.nowBtnClick = function () {
            PlayControlManager.serverDate().then(function (result) {
                $scope.data.onlineTime = new Date(result.data);
            })
        }
        $scope.endDateClick = function () {
            $scope.data.offlineTime = new Date(2030, 0, 1);

        }




        $scope.popup2={};
        $scope.popup1={};
            $scope.popup2Open = function () {
                $scope.popup2.opened=true
                $scope.optStart2 ={minDate: $scope.data.onlineTime?$scope.data.onlineTime:new Date()}
            }
        $scope.popup1Open = function () {
            $scope.popup1.opened=true
            $scope.optStart ={maxDate: $scope.data.offlineTime,minDate:new Date()}
        }

        $scope.modelOk = function () {
            var tmp = {
                onlineTime: $filter("date")($scope.data.onlineTime, "yyyy-MM-dd"),
                offlineTime: $filter("date")($scope.data.offlineTime, "yyyy-MM-dd")
            }
            PlayControlManager.albumsPlayOnAndOffAdjust(ids, tmp).then(function (result) {
                if (result.data.c == "s") {
                    $uibModalInstance.close("ok");

                } else {
                    $uibModalInstance.close("error");

                }

            })


        };

        $scope.modelCancel = function () {
            $uibModalInstance.close("cancel");
        };


    }])

